package cn.evun.tms.generator.task;

import cn.evun.tms.generator.framework.AbstractApplicationTask;
import cn.evun.tms.generator.framework.context.ApplicationContext;
import cn.evun.tms.generator.handler.BaseHandler;
import cn.evun.tms.generator.handler.impl.ShowPageHandler;
import cn.evun.tms.generator.model.EntityInfo;
import cn.evun.tms.generator.model.ShowPageInfo;

import java.util.List;

public class ShowPageTask extends AbstractApplicationTask {

	private static String SHOWPAGE_FTL = "template/ShowPage.ftl";

	@SuppressWarnings("unchecked")
	@Override
	protected boolean doInternal(ApplicationContext context) throws Exception {
		logger.info("开始生成showpage。。。");

		List<ShowPageInfo> showPageInfos = (List<ShowPageInfo>) context.getAttribute("showPageInfos");
		List<EntityInfo> dtoInfos = (List<EntityInfo>) context.getAttribute("entityInfos");

		BaseHandler<ShowPageInfo> baseHandler = null;

		for (int i = 0; i < showPageInfos.size(); i++) {
			ShowPageInfo showPageInfo = showPageInfos.get(i);
			EntityInfo dtoInfo = dtoInfos.get(i);
			showPageInfo.setEntityInfo(dtoInfo);
			baseHandler = new ShowPageHandler(SHOWPAGE_FTL, showPageInfo);
			baseHandler.execute(context);
		}



		logger.info("结束生成showpage。。。");
		return false;
	}


}
